package com.why.controller.sentinel;

import com.why.service.JedisClusterStringService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @Description
 * @Author why
 * @Version 1.0.0
 * @Since 1.0
 * @Date 2022/8/18
 */
//@RestController
//@RequestMapping("/string")
@Slf4j
public class StringController {

    @Autowired
    private JedisClusterStringService stringService;

    /**
     * set 存入一个key和值
     *
     * @param key
     * @param value result : OK
     */
    @RequestMapping("/set")
    public void set(String key, String value) {
        String result = stringService.set(key, value);
        log.info("string set command result : {}", result);
    }

    /**
     * 读取一个key的值
     *
     * @param key result: value 值
     */
    @GetMapping("/get")
    public void get(String key) {
        String result = stringService.get(key);
        log.info("string get command result : {}", result);
    }

    @PostMapping("/del")
    public void del(String key) {
        Long result = stringService.del(key);
        log.info("string del command result : {}", result);
    }

    /**
     *  mset 设置多个kv
     */
    @PostMapping("/mset")
    public void mset() {
        String result = stringService.mset();
        log.info("string mset command result : {}", result);
    }

    /**
     * api包分布式锁简单实现
     */
    @GetMapping("/tryLock")
    public void tryLock(String key) {
        stringService.tryLock(key);
    }
}
